#include "SALT_ObjectContainer.h"

namespace SALT{
	namespace Objects{
		DrawableContainer::DrawableContainer():DrawableObject(){
		}
		DrawableContainer::~DrawableContainer(){
		}
		DrawableObject* DrawableContainer::addObject(DrawableObject *obj){
			this->_children.push_back(obj);
			return obj;
		}
		DrawableObject* DrawableContainer::removeObject(DrawableObject* obj){
			std::vector<DrawableObject*>::iterator it=this->_children.begin();
			std::vector<DrawableObject*>::iterator end=this->_children.end();
			for(;it!=end;it++){
				if(*it==obj){
					this->_children.erase(it);
					break;
				}
			}
			return obj;
		}
		int DrawableContainer::update(){
			for(unsigned int i=0,l=this->_children.size();i<l;i++)
				this->_children[i]->update();
			return 0;
		}
		int DrawableContainer::draw(SALT::Graphics::SDLGraphicsManager *gm){
			gm->pushClip(&(this->_position));
			for(unsigned int i=0,l=this->_children.size();i<l;i++)
				this->_children[i]->draw(gm);
			gm->popClip();
			return 0;
		}
		EventContainer::EventContainer():EventObject(){
		}
		EventContainer::~EventContainer(){
		}
		EventObject* EventContainer::addObject(EventObject *obj){
			this->_children.push_back(obj);
			return obj;
		}
		EventObject* EventContainer::removeObject(EventObject* obj){
			std::vector<EventObject*>::iterator it=this->_children.begin();
			std::vector<EventObject*>::iterator end=this->_children.end();
			for(;it!=end;it++){
				if(*it==obj){
					this->_children.erase(it);
					break;
				}
			}
			return obj;
		}
		int EventContainer::handleEvent(SDL_Event* ev){
			for(unsigned int i=0,l=this->_children.size();i<l;i++)
				this->_children[i]->handleEvent(ev);
			return 0;
		}
	}
}